{include file="default/base/seller_top" /}
<div class="seller_main w1200">
    {include file="default/base/seller_left" /}
    <div class="seller_right">
        <style type="text/css">
            #fixedNavBar {
                filter: progid:DXImageTransform.Microsoft.gradient(enabled='true', startColorstr='#CCFFFFFF', endColorstr='#CCFFFFFF');
                background: rgba(255, 255, 255, 0.8);
                width: 90px;
                margin-left: 600px;
                border-radius: 4px;
                position: fixed;
                z-index: 999;
                top: 172px;
                left: 50%;
            }

            #fixedNavBar h3 {
                font-size: 12px;
                line-height: 24px;
                text-align: center;
                margin-top: 4px;
            }

            #fixedNavBar ul {
                width: 80px;
                margin: 0 auto 5px auto;
            }

            #fixedNavBar li {
                margin-top: 5px;
            }

            #fixedNavBar li a {
                font-family: Arial, Helvetica, sans-serif;
                font-size: 12px;
                line-height: 20px;
                background-color: #F5F5F5;
                color: #999;
                text-align: center;
                display: block;
                height: 20px;
                border-radius: 10px;
            }

            #fixedNavBar li a:hover {
                color: #FFF;
                text-decoration: none;
                background-color: #27a9e3;
            }
            .btn-small {
    height: 30px;
    line-height: 30px;
    padding: 0 10px;
    font-size: 12px;
    width: 50px;
    color: wheat;
    margin-right: 50px;
}
        </style>

        <div id="fixedNavBar">
            <h3>{$Think.lang.page_navigation}</h3>
            <ul>
                <li><a id="demo1Btn" href="#demo1" class="demoBtn">{$Think.lang.basic_information}</a></li>
                <li><a id="demo2Btn" href="#demo2" class="demoBtn">{$Think.lang.detailed_description}</a></li>
              </ul>
        </div>
        <div class="seller_items">
            {include file="default/base/seller_items" /}
        </div>
        {if isset($edit_goods_sign)}
        {else /}
        <ul class="add-goods-step">
            <li><i class="icon iconfont">&#xe600;</i>
                <h6>STEP.1</h6>
                <h2>{$Think.lang.select_category}</h2>
                <i class="arrow iconfont">&#xe687;</i> </li>
            <li class="current"><i class="icon iconfont">&#xe731;</i>
                <h6>STEP.2</h6>
                <h2>填写基本信息</h2>
                <i class="arrow iconfont">&#xe687;</i></li>
            <li><i class="icon iconfont">&#xe731;</i>
                <h6>STEP.3</h6>
                <h2>完善商品信息</h2>
                <i class="arrow iconfont">&#xe687;</i> </li>
            <li><i class="icon iconfont">&#xe6a2;</i>
                <h6>STEP.4</h6>
                <h2>{$Think.lang.store_goods_index_upload_goods_pic}</h2>

        </ul>
        {/if}
        <div class="item-publish">
            <form method="post" id="goods_form"
                  action="{if isset($edit_goods_sign)}{:url('sellergoodsinfomessage/edit_save_goods')}{else/}{:url('Sellergoodsadd/save_goods')}{/if}"
                  enctype="multipart/form-data">
                <input type="hidden" name="commonid" value="{$goods.goods_commonid|default=''}"/>
                <input type="hidden" name="type_id" value="{$goods_class.type_id|default=''}"/>
                <input type="hidden" name="edit_type" value="{$edit_type|default=''}"/>
                <div class="dssc-form-goods">
                    <h3 id="demo1">{$Think.lang.store_goods_index_goods_base_info}</h3>
                    <!--分类-->
                    <dl>
                        <dt>{$Think.lang.store_goods_index_goods_class}{$Think.lang.ds_colon}</dt>
                        <dd id="gcategory"> {$goods_class.gctag_name|default=''}
                            <a class="dssc-btn"
                               href="{if isset($edit_goods_sign)}{:url('sellergoodsinfomessage/edit_class',['commonid'=>$goods['goods_commonid']])}{else/}{:url('Sellergoodsadd/add_step_one')}{/if}">{$Think.lang.ds_edit}</a>
                            <input type="hidden" id="cate_id" name="cate_id" value="{$goods_class.gc_id|default=''}"
                                   class="text"/>
                            <input type="hidden" name="cate_name" value="{$goods_class.gctag_name|default=''}"
                                   class="text"/>
                        </dd>
                    </dl>


                    <!--名称-->
                    <dl>
                        <dt><i class="required">*</i>{$Think.lang.store_goods_index_goods_name}{$Think.lang.ds_colon}
                        </dt>
                        <dd>
                            <input name="g_name" type="text" class="text w400" value="{$goods.goods_name|default=''}"/>
                            <span></span>
                            <!-- <p class="hint">{$Think.lang.store_goods_index_goods_name_help}</p> -->
                    <p class="hint">注意：商品名称中不能添加空格，{$Think.lang.store_goods_index_goods_name_help}</p>        
                        </dd>
                    </dl>
                    <!--成本价-->
                    <!-- <dl>
                        <dt>成本价{$Think.lang.ds_colon}
                        </dt>
                        <dd>
                            <input name="goods_marketprice" type="text" class="text w400" value="{$goods.goods_marketprice|default=''}"/>
                            <span></span>
                        </dd>
                    </dl> -->
                    <!--销售价-->
                    <dl>
                        <dt>出厂价{$Think.lang.ds_colon}
                        </dt>
                        <dd>
                            <input name="goods_price" type="text" class="text w400" value="{$goods.goods_price|default=''}"/>
                            <span></span>
                        </dd>
                    </dl>
                    <!--库存-->
                    <dl>
                        <dt>库存{$Think.lang.ds_colon}
                        </dt>
                        <dd>
                            <input name="goods_storage" type="text" class="text w400" value="{$goods.skus|default=''}"/>
                            <span></span>
                        </dd>
                    </dl>
                    <!--库存安全值-->
                    <dl>
                        <dt>库存安全值{$Think.lang.ds_colon}
                        </dt>
                        <dd>
                            <input name="goods_storage_alarm" type="text" class="text w400" value="{$goods.goods_storage_alarm|default=''}"/>
                            <span></span>
                        </dd>
                    </dl>
                    <!--品牌-->
                    <dl style="overflow: visible;">
                        <dt>{$Think.lang.store_goods_index_goods_brand}{$Think.lang.ds_colon}</dt>
                        <dd>
                            <div class="dssc-brand-select">
                                <div class="selection">
                                    <input name="b_name" id="b_name" value="{$goods.brand_name|default=''}" type="text"
                                           class="text w180" readonly="readonly"/>
                                    <input type="hidden" name="b_id" id="b_id" value="{$goods.brand_id|default=''}"/>
                                    <em class="add-on" dstype="add-on"><i class="iconfont">&#xe73a;</i></em></div>
                                <div class="dssc-brand-select-container">
                                    <div class="brand-index" data-tid="{$goods_class.type_id}"
                                         data-url="{:url('Sellergoodsadd/ajax_get_brand')}">
                                        <div class="letter" dstype="letter">
                                            <ul>
                                                <li><a href="javascript:void(0);"
                                                       data-letter="all">{$Think.lang.ds_all}</a></li>
                                                <li><a href="javascript:void(0);" data-letter="A">A</a></li>
                                                <li><a href="javascript:void(0);" data-letter="B">B</a></li>
                                                <li><a href="javascript:void(0);" data-letter="C">C</a></li>
                                                <li><a href="javascript:void(0);" data-letter="D">D</a></li>
                                                <li><a href="javascript:void(0);" data-letter="E">E</a></li>
                                                <li><a href="javascript:void(0);" data-letter="F">F</a></li>
                                                <li><a href="javascript:void(0);" data-letter="G">G</a></li>
                                                <li><a href="javascript:void(0);" data-letter="H">H</a></li>
                                                <li><a href="javascript:void(0);" data-letter="I">I</a></li>
                                                <li><a href="javascript:void(0);" data-letter="J">J</a></li>
                                                <li><a href="javascript:void(0);" data-letter="K">K</a></li>
                                                <li><a href="javascript:void(0);" data-letter="L">L</a></li>
                                                <li><a href="javascript:void(0);" data-letter="M">M</a></li>
                                                <li><a href="javascript:void(0);" data-letter="N">N</a></li>
                                                <li><a href="javascript:void(0);" data-letter="O">O</a></li>
                                                <li><a href="javascript:void(0);" data-letter="P">P</a></li>
                                                <li><a href="javascript:void(0);" data-letter="Q">Q</a></li>
                                                <li><a href="javascript:void(0);" data-letter="R">R</a></li>
                                                <li><a href="javascript:void(0);" data-letter="S">S</a></li>
                                                <li><a href="javascript:void(0);" data-letter="T">T</a></li>
                                                <li><a href="javascript:void(0);" data-letter="U">U</a></li>
                                                <li><a href="javascript:void(0);" data-letter="V">V</a></li>
                                                <li><a href="javascript:void(0);" data-letter="W">W</a></li>
                                                <li><a href="javascript:void(0);" data-letter="X">X</a></li>
                                                <li><a href="javascript:void(0);" data-letter="Y">Y</a></li>
                                                <li><a href="javascript:void(0);" data-letter="Z">Z</a></li>
                                                <li><a href="javascript:void(0);" data-letter="0-9">{$Think.lang.ds_other}</a>
                                                </li>
                                                <li><a href="javascript:void(0);" data-empty="0">{$Think.lang.sellergoodsadd_empty}</a>
                                                </li>
                                            </ul>
                                        </div>
                                        <div class="search" dstype="search">
                                            <input name="search_brand_keyword" id="search_brand_keyword" type="text"
                                                   class="text"
                                                   placeholder="{$Think.lang.brand_name_keyword_search}"/><a
                                                href="javascript:void(0);" class="dssc-btn-mini"
                                                style="vertical-align: top;">Go</a></div>
                                    </div>
                                    <div class="brand-list" dstype="brandList">
                                        <ul dstype="brand_list">
                                            {notempty name="brand_list"}
                                            {foreach name="brand_list" item="val"}
                                            <li data-id='{$val.brand_id}' data-name='{$val.brand_name}'><em>{$val.brand_initial}</em>{$val.brand_name}
                                            </li>
                                            {/foreach}
                                            {/notempty}
                                        </ul>
                                    </div>
                                    <div class="no-result" dstype="noBrandList" style="display: none;">
                                        {$Think.lang.does_not_match}"<strong>{$Think.lang.search_keywords}</strong>"{$Think.lang.conditional_brand}
                                    </div>
                                </div>
                            </div>
                        </dd>
                    </dl>
                    <!-- 规格 -->
                     <?php if(is_array($spec_list) && !empty($spec_list)){?>
                     <?php $i = '0';?>
                     <?php foreach ($spec_list as $k=>$val){?>
                     <dl ds_type="spec_group_dl_{$i}" dstype="spec_group_dl" class="spec-bg" {if $k == '1'}spec_img="t"{/if}>
                        <dt>
                          <input name="sp_name[{$k}]" type="text" class="text w60 tip2 tr" title="{$Think.lang.specifications_instructions2}" value="<?php if (isset($goods['spec_name'][$k])) { echo $goods['spec_name'][$k];} else {echo $val['sp_name'];}?>" maxlength="10" dstype="spec_name" data-param="{id:<?php echo $k;?>,name:'<?php echo $val['sp_name'];?>'}"/>
                          {$Think.lang.ds_colon}
                          </dt>
                        <dd {if $k == '1'}dstype="sp_group_val"{/if}>
                          <ul class="spec">
                    <?php if(is_array($val['value'])){?>
                    {foreach name="$val.value" item="v" }
                    <li><span dstype="input_checkbox">
                      <input type="checkbox" value="{$v.spvalue_name}" ds_type="{$v.spvalue_id}" {if $k == '1'}class="sp_val"{/if} name="sp_val[{$k}][{$v.spvalue_id}]">
                      </span><span dstype="pv_name">{$v.spvalue_name}</span>
                    </li>
                    {/foreach}
                    <?php }?>
                    <li data-param="{gc_id:{$goods_class.gc_id},sp_id:{$k},url:'{:url('Sellergoodsadd/ajax_add_spec')}'}">
                      <div dstype="specAdd1"><a href="javascript:void(0);" class="dssc-btn" dstype="specAdd"><i class="iconfont">&#xe6db;</i>{$Think.lang.add_specification_value}</a></div>
                      <div dstype="specAdd2" style="display:none;">
                        <input class="text w60" type="text" placeholder="{$Think.lang.specification_value_name}" maxlength="20">
                        <a href="javascript:void(0);" dstype="specAddSubmit" class="dssc-btn dssc-btn-acidblue ml5 mr5">{$Think.lang.ds_ok}</a><a href="javascript:void(0);" dstype="specAddCancel" class="dssc-btn dssc-btn-orange">{$Think.lang.ds_cancel}</a></div>
                    </li>
                          </ul>
                          <?php if(isset($edit_goods_sign) && $k == '1'){?>
                          <p class="hint">{$Think.lang.specifications_instructions3}</p>
                          <?php }?>
                        </dd>
                     </dl>
                     <?php $i++;?>
                     <?php }?>
                     <?php }?>
                     <dl ds_type="spec_dl" class="spec-bg" style="display:none; overflow: visible;">
                        <dt>{$Think.lang.srore_goods_index_goods_stock_set}{$Think.lang.ds_colon}</dt>
                        <dd class="spec-dd">
                          <table border="0" cellpadding="0" cellspacing="0" class="spec_table">
                    <thead>
                      {notempty name="spec_list"}
                        <?php $spec_i=0; ?>
                      {foreach name="spec_list" item="val" key="k" }
                    <th dstype="spec_name_{$k}" data-type="spec_name_<?php echo $spec_i; ?>" style="display:none"><?php if (isset($goods['spec_name'][$k])) { echo $goods['spec_name'][$k];} else {echo $val['sp_name'];}?></th>
                      <?php $spec_i++; ?>
                        {/foreach}
                      {/notempty}
                      <!-- <th class="w90"><span class="red">*</span>{$Think.lang.market_price}
                        <div class="batch"><i class="iconfont" title="{$Think.lang.batch_operation}">&#xe731;</i>
                          <div class="batch-input" style="display:none;">
                            <h6>{$Think.lang.batch_setting_price}：</h6>
                            <a href="javascript:void(0)" class="close">X</a>
                            <input name="" type="text" class="text price" />
                            <a href="javascript:void(0)" class="dssc-btn-mini" data-type="marketprice">{$Think.lang.set}</a><span class="arrow"></span></div>
                        </div></th> -->
                      <th class="w90"><span class="red">*</span>出厂价
                        <div class="batch"><i class="iconfont" title="{$Think.lang.batch_operation}">&#xe731;</i>
                          <div class="batch-input" style="display:none;">
                            <h6>{$Think.lang.batch_setting_price}：</h6>
                            <a href="javascript:void(0)" class="close">X</a>
                            <input name="" type="text" class="text price" />
                            <a href="javascript:void(0)" class="dssc-btn-mini" data-type="price">{$Think.lang.set}</a><span class="arrow"></span></div>
                        </div></th>
                      <th class="w60"><span class="red">*</span>{$Think.lang.store_goods_index_stock}
                        <div class="batch"><i class="iconfont" title="{$Think.lang.batch_operation}">&#xe731;</i>
                          <div class="batch-input" style="display:none;">
                            <h6>{$Think.lang.batch_setting_inventory}：</h6>
                            <a href="javascript:void(0)" class="close">X</a>
                            <input name="" type="text" class="text stock" />
                            <a href="javascript:void(0)" class="dssc-btn-mini" data-type="stock">{$Think.lang.set}</a><span class="arrow"></span></div>
                        </div></th>
                      <th class="w70">{$Think.lang.warning_value}
                        <div class="batch"><i class="iconfont" title="{$Think.lang.batch_operation}">&#xe731;</i>
                          <div class="batch-input" style="display:none;">
                            <h6>{$Think.lang.set_warning_value_batches}：</h6>
                            <a href="javascript:void(0)" class="close">X</a>
                            <input name="" type="text" class="text stock" />
                            <a href="javascript:void(0)" class="dssc-btn-mini" data-type="alarm">{$Think.lang.set}</a><span class="arrow"></span></div>
                        </div></th>
                      <!-- <th class="w100">{$Think.lang.store_goods_index_goods_no}</th> -->
                      <th class="w100">操作</th>
                        </thead>
                    <tbody ds_type="spec_table">
                    </tbody>
                          </table>
                          <p class="hint">{$Think.lang.click}<i class="iconfont">&#xe731;</i>{$Think.lang.modify_value_column_batches}。</p>
                        </dd>
                     </dl>
                    <!--轮播图视频-->
                    <dl>
                        <dt><i class="required"></i>轮播图视频：</dt>
                        <dd>
                            <div class="dssc-goods-default-pic">
                                <div class="goodspic-uplaod">
                                    <span></span>
                                    <input type="hidden" name="videos" id="video_name"
                                           value="{$goods.videos|default=''}"/>
                                    <input type="file" hidefocus="true" name="video" id="videos" data-action="{:url('Sellergoodsadd/ajax_videos')}">
                                    </span>
                                    <p class="hint">请上传后缀名为：*.avi *.mov *.wmv *.mp4 的文件</p>
                                </div>
                            </div>
                            <p class="vide">
                             <?php if(isset($edit_goods_sign)&&!empty($goods['videos'])){  ?>
                                 <video width="300" height="180" controls>
                   <source src="{$http_name}/{$goods.videos}" type="video/mp4">
                 </video>
                                <input type="button" value="删除" style=" width: 44px; font-size: 14px;" id="del_videos"> <?php  } ?>
             </p>
                            <div id="demo">
             </div>
                        </dd>
                    </dl>
                    <!--  商品详情描述 -->
                    <h3 id="demo2">{$Think.lang.store_goods_index_goods_detail_info}</h3>
                    {notempty name="attr_list"}
                    <dl>
                        <dt>{$Think.lang.store_goods_index_goods_attr}111{$Think.lang.ds_colon}</dt>
                        <dd>
                            {foreach name="attr_list" item="val" key="k" }
                            <span class="mr30">
          <label class="mr5">{$val.attr_name}</label>
          <input type="hidden" name="attr[{$k}][name]" value="{$val.attr_name}"/>
          {notempty name="val"}
          <select name="" attr="attr[{$k}][__NC__]" ds_type="attr_select">
            <option value='' ds_type='0'>{$Think.lang.ds_please_choose}</option>
            {foreach name="$val.value" item="v"}
            <option value="{$v.attrvalue_name}"
              <?php if(isset($attr_checked) && in_array($v['attrvalue_id'], $attr_checked)){?>
              selected="selected"<?php }?> ds_type="{$v.attrvalue_id}">{$v.attrvalue_name}</option>
              {/foreach}
          </select>
          {/notempty}
          </span>
                            {/foreach}
                        </dd>
                    </dl>
                    {/notempty}
                    <dl>
                        <dt>{$Think.lang.store_goods_index_goods_desc}{$Think.lang.ds_colon}</dt>
                        <dd id="dsProductDetails" style="z-index: 99;position: relative">
                            <div class="tabs">
                                <ul class="ui-tabs-nav">
                                    <li class="ui-tabs-selected"><a href="#panel-1"><i class="iconfont">&#xe60c;</i>
                                        商品详情</a></li>
                                </ul>
                                <div id="panel-1" class="ui-tabs-panel">
                                    {:build_editor(['name'=>'goods_body','content'=>htmlspecialchars_decode($goods.goods_body)])}
                                    <textarea name="goods_body" id="goods_body"></textarea>
                                    <div class="hr8">

                                        <a class="dssc-btn mt5" dstype="show_desc"
                                           href="{:url('Selleralbum/pic_list',['item'=>'des'])}"><i class="iconfont">&#xe72a;</i>{$Think.lang.store_goods_album_insert_users_photo}</a>
                                        <a href="javascript:void(0);" dstype="del_desc" class="dssc-btn mt5"
                                           style="display: none;"><i class=" iconfont">&#xe67a;</i>{$Think.lang.close_album}</a>
                                        <span> 提示：支持jpg，jpeg，png格式图片</span>
                                    </div>
                                    <p id="des_demo"></p>
                                </div>
                                <div class="dssc-upload-btn"><a href="javascript:void(0);"><span>
                  <input type="file" hidefocus="true" size="1" class="input-file" name="add_album" id="add_album"
                         multiple="multiple">
                  </span>
                                    <p><i class="iconfont" data_type="0" dstype="add_album_i">&#xe733;</i>{$Think.lang.store_goods_brand_pic_upload}
                                    </p>
                                </a>
                                </div>
                            </div>
                        </dd>
                    </dl>

                    <div class="bottom tc hr32" style="margin-bottom: 30px;
">
                        <input type="hidden" name="add_type" id="add_type" value="">
                        <input type="hidden" name="is_spec" id="is_spec" value="1">

                        <?php if (!isset($edit_goods_sign)) { ?>
                        <input type="button" class="dssc-btn dssc-btn-acidblue"  style="margin-top: 10px;width: 260px;margin-left: -424px;height: 40px;font-size: 16px;"
                               value="暂存商品信息" id="zan_submit"/>
                        <input type="button" class="submit" id='button_submit' style="margin-left: 548px;margin-top: -39px;"
                               value="<?php if (isset($edit_goods_sign)) {echo lang('ds_submit');} else {?>{$Think.lang.store_goods_add_next}，完善商品信息<?php }?>" data-action="{if isset($edit_goods_sign)}1{else/}2{/if}"/>
                        <?php }else{ ?>
                        <input type="button" class="dssc-btn dssc-btn-acidblue"  style="margin-top: 10px;width: 260px;margin-left: -60px;height: 40px;font-size: 16px;"
                               value="暂存商品信息" id="zan_submit"/>
                        <?php }?>
                    </div>
            </form>
        </div>


        <script src="{$Think.PLUGINS_SITE_ROOT}/jquery.ajaxContent.pack.js"></script>
        <script src="{$Think.PLUGINS_SITE_ROOT}/mlselection.js"></script>
        <script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/js/fileupload/jquery.iframe-transport.js"
                charset="utf-8"></script>
        <script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/js/fileupload/jquery.ui.widget.js"
                charset="utf-8"></script>
        <script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/js/fileupload/jquery.fileupload.js"
                charset="utf-8">
        </script>

        <script src="{$Think.PLUGINS_SITE_ROOT}/jquery.mousewheel.js"></script>

        <script src="{$Think.PLUGINS_SITE_ROOT}/layui/layui.js"></script>

        <script type="text/javascript" src="{$Think.PLUGINS_SITE_ROOT}/jquery.charCount.js"></script>


        <!--[if lt IE 8]>
        <script src="{$Think.BASE_SITE_ROOT}/js/json2.js"></script>
        <![endif]-->
        <script src="{$Think.HOME_SITE_ROOT}/js/sellergoods_add_step2.js"></script>


        <script type="text/javascript">


            $(document).ready(function(){
                //编辑视频删除
                $('#del_videos').click(function(){
                    $('.vide').empty();
                    $("#video_name").val('');
                });


                // 商品相关权限关联选择
                $('#store_goods_add,#store_goods_online,#store_goods_offline').on('click', function() {
                    if($(this).prop('checked')) {
                        store_goods_select(true);
                    } else {
                        store_goods_select(false);
                    }
                });

                function store_goods_select(state) {
                    $('#store_goods_add').prop('checked', state);
                    $('#store_goods_online').prop('checked', state);
                    $('#store_goods_offline').prop('checked', state);
                }
            });

            // 按规格存储规格值数据
            var spec_group_checked = new Array();
            <?php for($i=0; $i<$sign_i; $i++){ ?>
                spec_group_checked["<?php echo $i;?>"]='';
            <?php } ?>
            var str = '';
            var V = new Array();

            <?php for ($i=0; $i<$sign_i; $i++){?>
                var spec_group_checked_<?php echo $i;?> = new Array();
            <?php }?>

            $(function(){
                $('dl[dstype="spec_group_dl"]').on('click', 'span[dstype="input_checkbox"] > input[type="checkbox"]',function(){
                    into_array();
                    goods_stock_set();
                });

                // 提交后不没有填写的价格或库存的库存配置设为默认价格和0
                // 库存配置隐藏式 里面的input加上disable属性
                $('input[type="submit"]').click(function(){
                    $('input[data_type="price"]').each(function(){
                        if($(this).val() == ''){
                            $(this).val($('input[name="g_price"]').val());
                        }
                    });
                    $('input[data_type="stock"]').each(function(){
                        if($(this).val() == ''){
                            $(this).val('0');
                        }
                    });
                    $('input[data_type="alarm"]').each(function(){
                        if($(this).val() == ''){
                            $(this).val('0');
                        }
                    });
                    if($('dl[ds_type="spec_dl"]').css('display') == 'none'){
                        $('dl[ds_type="spec_dl"]').find('input').prop('disabled','disabled');
                    }
                });

            });

            // 将选中的规格放入数组
            function into_array(){
            <?php for ($i=0; $i<$sign_i; $i++){?>

                    spec_group_checked_<?php echo $i;?> = new Array();
                    $('dl[ds_type="spec_group_dl_<?php echo $i;?>"]').find('input[type="checkbox"]:checked').each(function(){
                        i = $(this).attr('ds_type');
                        v = $(this).val();
                        c = null;
                        if ($(this).parents('dl:first').attr('spec_img') == 't') {
                            c = 1;
                        }
                        spec_group_checked_<?php echo $i;?>[spec_group_checked_<?php echo $i;?>.length] = [v,i,c];
                    });

                    spec_group_checked["<?php echo $i;?>"] = spec_group_checked_<?php echo $i;?>;

                <?php }?>
            }

            // 生成库存配置
            function goods_stock_set(){
                //  店铺价格 商品库存改为只读
                $('input[name="g_price"]').attr('readonly','readonly').css('background','#E7E7E7 none');
                $('input[name="g_storage"]').attr('readonly','readonly').css('background','#E7E7E7 none');

                $('dl[ds_type="spec_dl"]').show();
                str = '<tr>';
            <?php recursionSpec(0,$sign_i);?>
                //生成字符串开始
                {notempty name="spec_list"}
                {foreach name="spec_list" item="val" key="k" }
                $('[data-type=spec_name_'+({$k})+']').hide();
                {/foreach}
                    {/notempty}
                        var total_length=0;
                        for(var i in checked_group){
                            $('[data-type=spec_name_'+(i)+']').show();
                            if(total_length==0){
                                total_length=1;
                            }
                            total_length=total_length*spec_group_checked[checked_group[i]].length;
                        }

                        var k=new Array();
                        var l=0;
                        var n=0;
                        for(var j=0;j<total_length;j++){
                            var spec_bunch='i_';
                            var sub_str='';
                            sub_str += '<input type="hidden" name="spec[spec_bunch][goods_id]" ds_type="spec_bunch|id" value="" />';
                            for(var i in checked_group){


                                if(typeof(k[checked_group[i]])=='undefined'){
                                    k[checked_group[i]]=0;
                                }
                                spec_bunch+=spec_group_checked[checked_group[i]][k[checked_group[i]]][1];
                                if (spec_group_checked[checked_group[i]][k[checked_group[i]]][2] != null) { sub_str += '<input type="hidden" name="spec[spec_bunch][color]" value="'+spec_group_checked[checked_group[i]][k[checked_group[i]]][1]+'" />';}
                                sub_str +='<td><input type="hidden" name="spec[spec_bunch][sp_value]['+spec_group_checked[checked_group[i]][k[checked_group[i]]][1]+']" value="'+spec_group_checked[checked_group[i]][k[checked_group[i]]][0]+'" />'+spec_group_checked[checked_group[i]][k[checked_group[i]]][0]+'</td>';
                                //checked_group存储选中的规格的键
                                //spec_group_checked存储选中的规格的值
                                //k表示规格值的指针
                                //total_length表示选中规格的总长度

                                //由最后一个规格开始遍历，如果满了，则前面的规格指针增加，同时当前指针指置0

                                //最后一个规格项
                                //最后规格的指针增加
                                //最后一个规格的指针满了
                                //从最后的规格开始向前遍历
                                //如果规格指针没有满
                                //规格指针增加
                                //规格指针复位
                                if(i==(checked_group.length-1)){
                                    k[checked_group[i]]++;
                                    if(k[checked_group[i]]==spec_group_checked[checked_group[i]].length){
                                        for(var m = (checked_group.length-1);m>=0;m--){
                                            if(k[checked_group[m]]<(spec_group_checked[checked_group[m]].length-1)){
                                                k[checked_group[m]]++;
                                                break;
                                            }else{
                                                k[checked_group[m]]=0;
                                            }
                                        }
                                    }
                                }
                            }

                            sub_str +='<td><input class="text price" type="text" name="spec[spec_bunch][price]" data_type="price" ds_type="spec_bunch|price" value="" /><em class="add-on"><i class="iconfont">&#xe65c;</i></em></td><td><input class="text stock" type="text" name="spec[spec_bunch][stock]" data_type="stock" ds_type="spec_bunch|stock" value="" /></td><td><input class="text stock" type="text" name="spec[spec_bunch][alarm]" data_type="alarm" ds_type="spec_bunch|alarm" value="" /></td><td><button type="button" onclick="delete2($(this))"  class="btn btn-small layui-btn-danger">删除</button></td></tr>';
                            sub_str=sub_str.replace(/spec_bunch/g, spec_bunch);
                            str +=sub_str;
                        }
                        //生成字符串结束

                        if(str == '<tr>'){
                            //  店铺价格 商品库存取消只读
                            $('input[name="g_price"]').removeAttr('readonly').css('background','');
                            $('input[name="g_storage"]').removeAttr('readonly').css('background','');
                            $('dl[ds_type="spec_dl"]').hide();
                        }else{
                            $('tbody[ds_type="spec_table"]').empty().html(str)
                                .find('input[ds_type]').each(function(){
                                s = $(this).attr('ds_type');
                                try{$(this).val(V[s]);}catch(ex){$(this).val('');};
                                if ($(this).attr('data_type') == 'marketprice' && $(this).val() == '') {
                                    $(this).val($('input[name="g_marketprice"]').val());
                                }
                                if ($(this).attr('data_type') == 'price' && $(this).val() == ''){
                                    $(this).val($('input[name="g_price"]').val());
                                }
                                if ($(this).attr('data_type') == 'stock' && $(this).val() == ''){
                                    $(this).val('0');
                                }
                                if ($(this).attr('data_type') == 'alarm' && $(this).val() == ''){
                                    $(this).val('0');
                                }
                            }).end()
                                .find('input[data_type="stock"]').change(function(){
                                computeStock();    // 库存计算
                            }).end()
                                .find('input[data_type="price"]').change(function(){
                                computePrice();     // 价格计算
                            }).end()
                                .find('input[ds_type]').change(function(){
                                s = $(this).attr('ds_type');
                                V[s] = $(this).val();
                            });
                        }
                    }

                <?php
                    /**
                     *
                     *
                     *  生成需要的js循环。递归调用  PHP
                     *
                     *  形式参考 （ 2个规格）
                     *  $('input[type="checkbox"]').click(function(){
                     *      str = '';
                     *      for (var i=0; i<spec_group_checked[0].length; i++ ){
                     *      td_1 = spec_group_checked[0][i];
                     *          for (var j=0; j<spec_group_checked[1].length; j++){
                     *              td_2 = spec_group_checked[1][j];
                     *              str += '<tr><td>'+td_1[0]+'</td><td>'+td_2[0]+'</td><td><input type="text" /></td><td><input type="text" /></td><td><input type="text" /></td>';
                     *          }
                     *      }
                     *      $('table[class="spec_table"] > tbody').empty().html(str);
                     *  });
                     */
                    function recursionSpec($len,$sign) {
                        echo "var checked_group=new Array();\n";
                        for($i=0; $i< $sign; $i++){
                            echo "if(spec_group_checked['".$i."'].length>0){ checked_group.push('".$i."'); }\n";
                        }


                    }

                        ?>

                <?php if (!empty($goods) && !empty($sp_value) && !empty($spec_checked) && !empty($spec_list)){?>

//  编辑商品时处理JS
                    $(function(){
                        var E_SP = new Array();
                        var E_SPV = new Array();
                        {php}
                        $string = '';
                        foreach ($spec_checked as $v) {
                            $string .= "E_SP[".$v['id']."] = '".$v['name']."';";
                        }
                        echo $string;
                        echo "\n";
                        $string = '';
                        foreach ($sp_value as $k=>$v) {
                            $string .= "E_SPV['".$k."'] = '".$v."';";
                        }
                        echo $string;
                        {/php}
                            V = E_SPV;
                            $('dl[ds_type="spec_dl"]').show();
                            $('dl[dstype="spec_group_dl"]').find('input[type="checkbox"]').each(function(){

                                //  店铺价格 商品库存改为只读
                                $('input[name="g_price"]').attr('readonly','readonly').css('background','#E7E7E7 none');
                                $('input[name="g_storage"]').attr('readonly','readonly').css('background','#E7E7E7 none');
                                s = $(this).attr('ds_type');
                                if (!(typeof(E_SP[s]) == 'undefined')){
                                    $(this).prop('checked',true);
                                    v = $(this).parents('li').find('span[dstype="pv_name"]');
                                    if(E_SP[s] != ''){
                                        $(this).val(E_SP[s]);
                                        v.html('<input type="text" maxlength="20" value="'+E_SP[s]+'" />');
                                    }else{
                                        v.html('<input type="text" maxlength="20" value="'+v.html()+'" />');
                                    }
                                    change_img_name($(this));     // 修改相关的颜色名称
                                }
                            });

                            into_array(); // 将选中的规格放入数组
                            str = '<tr>';
                        <?php recursionSpec(0,$sign_i);?>

                            //生成字符串开始

                            var total_length=0;
                            for(var i in checked_group){
                                $('[data-type=spec_name_'+(i)+']').show();
                                if(total_length==0){
                                    total_length=1;
                                }
                                total_length=total_length*spec_group_checked[checked_group[i]].length;
                            }

                            var k=new Array();
                            var l=0;
                            var n=0;
                            for(var j=0;j<total_length;j++){
                                var spec_bunch='i_';
                                var sub_str='';
                                sub_str += '<input type="hidden" name="spec[spec_bunch][goods_id]" ds_type="spec_bunch|id" value="" />';
                                for(var i in checked_group){


                                    if(typeof(k[checked_group[i]])=='undefined'){
                                        k[checked_group[i]]=0;
                                    }
                                    spec_bunch+=spec_group_checked[checked_group[i]][k[checked_group[i]]][1];
                                    if (spec_group_checked[checked_group[i]][k[checked_group[i]]][2] != null) { sub_str += '<input type="hidden" name="spec[spec_bunch][color]" value="'+spec_group_checked[checked_group[i]][k[checked_group[i]]][1]+'" />';}
                                    sub_str +='<td><input type="hidden" name="spec[spec_bunch][sp_value]['+spec_group_checked[checked_group[i]][k[checked_group[i]]][1]+']" value="'+spec_group_checked[checked_group[i]][k[checked_group[i]]][0]+'" />'+spec_group_checked[checked_group[i]][k[checked_group[i]]][0]+'</td>';

                                    if(i==(checked_group.length-1)){
                                        k[checked_group[i]]++;
                                        if(k[checked_group[i]]==spec_group_checked[checked_group[i]].length){
                                            for(var m = (checked_group.length-1);m>=0;m--){
                                                if(k[checked_group[m]]<(spec_group_checked[checked_group[m]].length-1)){
                                                    k[checked_group[m]]++;
                                                    break;
                                                }else{
                                                    k[checked_group[m]]=0;
                                                }
                                            }
                                        }
                                    }
                                }

                               sub_str +='<td><input class="text price" type="text" name="spec[spec_bunch][price]" data_type="price" ds_type="spec_bunch|price" value="" /><em class="add-on"><i class="iconfont">&#xe65c;</i></em></td><td><input class="text stock" type="text" name="spec[spec_bunch][stock]" data_type="stock" ds_type="spec_bunch|stock" value="" /></td><td><input class="text stock" type="text" name="spec[spec_bunch][alarm]" data_type="alarm" ds_type="spec_bunch|alarm" value="" /></td><td><button type="button" onclick="delete2($(this))"  class="btn btn-small layui-btn-danger">删除</button></td></tr>';
                                sub_str=sub_str.replace(/spec_bunch/g, spec_bunch);
                                str +=sub_str;
                            }
                            //生成字符串结束


                            if(str == '<tr>'){
                                $('dl[ds_type="spec_dl"]').hide();
                                $('input[name="g_price"]').removeAttr('readonly').css('background','');
                                $('input[name="g_storage"]').removeAttr('readonly').css('background','');
                            }else{
                                $('tbody[ds_type="spec_table"]').empty().html(str)
                                    .find('input[ds_type]').each(function(){
                                    s = $(this).attr('ds_type');
                                    try{$(this).val(E_SPV[s]);}catch(ex){$(this).val('');};
                                }).end()
                                    .find('input[data_type="stock"]').change(function(){
                                    computeStock();    // 库存计算
                                }).end()
                                    .find('input[data_type="price"]').change(function(){
                                    computePrice();     // 价格计算
                                }).end()
                                    .find('input[type="text"]').change(function(){
                                    s = $(this).attr('ds_type');
                                    V[s] = $(this).val();
                                });
                            }
                        });
                <?php }?>

// TODO  删除规格
function delete2(obj){
    $(obj).parent().parent().parent()[0].removeChild($(obj).parent().parent()[0]);
}

            $(function () {

                $("#region").ds_region({show_deep: 2, tip_type: 1});
                //电脑端手机端tab切换
                $(".tabs").tabs();
                $.validator.addMethod('checkPrice', function (value, element) {
                    _g_price = parseFloat($('input[name="g_price"]').val());
                    _g_marketprice = parseFloat($('input[name="g_marketprice"]').val());
                    if (_g_price > _g_marketprice) {
                        return false;
                    } else {
                        return true;
                    }
                }, '<i class="iconfont">&#xe64c;</i>{$Think.lang.not_higher_than}');

                $('#area_id1').change(function () {
                    var htmls = '<option value="">请选择...</option>';
                    $('#area_id2').html(htmls);
                    var area_id = $(this).val();
                    var url = $(this).attr('data-action');
                    if (area_id == '0') {
                        var htmls = '<option value="">请选择...</option>';
                        $('#area_id2').html(htmls);
                    } else {
                        $.ajax({
                            //请求方式
                            type: "POST",
                            //请求地址
                            url: url,
                            //数据，json字符串
                            data: {'area_id': area_id},
                            //请求成功
                            success: function (result) {
                            
                                var htmls = '<option value="">请选择...</option>';
                                $.each(result, function (item, v) {
                                    htmls += "<option value='" + v.area_id + "'>" + v.area_name + "</option>";
                                });

                                $('#area_id2').html(htmls);
                            },
                            //请求失败，包含具体的错误信息
                            error: function (e) {
                                console.log(e.status);
                                console.log(e.responseText);
                            }
                        });
                    }
                });

                //轮播图视频上传
                $(document).on('change', '#videos', function () {
                    var files = document.getElementById('videos').files[0];
                    var formData = new FormData();
                    var obj = $(this);
                    formData.append('file', files);
                     var url = $(this).attr('data-action');
                     layer.msg('正在上传');
                     $.ajax({
                        //请求方式
                        type: "POST",
                        //请求地址
                        url: url,
                        data: formData,
                        cache: false,  //默认是true，但是一般不做缓存
                        processData: false, //用于对data参数进行序列化处理，这里必须false；如果是true，就会将FormData转换为String类型
                        contentType: false,  //一些文件上传http协议的关系，自行百度，如果上传的有文件，那么只能设置为false
                        //请求成功
                        success: function (result) {
                            if (result.msg == 1) {
                                $('.vide').empty();
                                $('#dataLoading').hide();
                                layer.msg('上传成功');
                                $("#video_name").val(result.files_name);
                            } else {
                                obj.val('');
                                $('#dataLoading').hide();
                                layer.msg('文件信息错误,请重新上传');
                                return false;
                            }

                        },
                        //请求失败，包含具体的错误信息
                        error: function (e) {
                            console.log(e.status);
                            console.log(e.responseText);
                        }
                    });

                });


                jQuery.validator.addMethod("checkFCodePrefix", function (value, element) {
                    return this.optional(element) || /^[a-zA-Z]+$/.test(value);
                }, '<i class="iconfont">&#xe64c;</i>{$Think.lang.prompt_information1}');

                
                $('#goods_form').validate({
                    errorPlacement: function (error, element) {
                        $(element).nextAll('span').append(error);
                    },
                    rules: {
                        g_name: {
                            required: true,
                            minlength: 3,
                            maxlength: 50
                        },
                        goods_body: {
                            required: true,
                        },
                    },
                    messages: {
                        g_name: {
                            required: '<i class="iconfont">&#xe64c;</i>{$Think.lang.store_goods_index_goods_name_null}',
                            minlength: '<i class="iconfont">&#xe64c;</i>{$Think.lang.store_goods_index_goods_name_help}',
                            maxlength: '<i class="iconfont">&#xe64c;</i>{$Think.lang.store_goods_index_goods_name_help}'
                        },
                        goods_body: {
                            required: '<i class="iconfont">&#xe64c;</i>不能为空'
                        },
                        b_name: {
                            required: '<i class="iconfont">&#xe64c;</i>不能为空'
                        },
                        goods_price: {
                            number: '请设置正确的数值',
                            min: '请设置正确的数值',
                        },
                        goods_storage: {
                            digits: '此数值需要是正整数',
                            min: '设置的数值需要大于零',
                        },
                        goods_storage_alarm: {
                            digits: '此数值需要是正整数',
                            min: '设置的数值需要大于零',
                        },
                    }
                });
                //提交下一步的
                $('#button_submit').click(function(){
                    var b_name = $('input[name="b_name"]').val();
                    if(b_name==''){
                        layer.msg('请选择品牌');return false;
                    }
                        var res =  $("#goods_form").valid();
                        if(res){
                            var url = $('form').attr('action');
                            $('#add_type').val('1');
                            $.ajax({
                                type: "POST",
                                url:url,
                                data:$('#goods_form').serialize(),// 你的formid
                                error: function(request) {
                                    alert("Connection error");
                                },
                                success: function(data) {
                                    if(data.code==0){
                                        layer.msg(data.msg);
                                        location.href=data.url;return false;
                                    }else if(data.code==-1){
                                        layer.msg(data.msg);return false;
                                    }else{
                                        layer.msg(data.msg);
                                        location.href=data.url;return false;
                                }
                                }
                            });
                        }

                });

                //暂存信息的
                $('#zan_submit').click(function(){
                    var b_name = $('input[name="b_name"]').val();
                    if(b_name==''){
                        layer.msg('请选择品牌');return false;
                    }
                    var res =  $("#goods_form").valid();
                    if(res){
                      //判断是否选中 复选框
                        var spec_values = [];
                        $('input[type="checkbox"]:checked').each(function () {
                            spec_values.push($(this).val());
                        });
                         if(spec_values==''){
                             $('#is_spec').val('2');
                         }
                        var url = $('form').attr('action');
                        $('#add_type').val('2');
                        $.ajax({
                            type: "POST",
                            url:url,
                            data:$('#goods_form').serialize(),// 你的formid
                            error: function(request) {
                                alert("Connection error");
                            },
                            success: function(data) {
                                if(data.code==0){
                                    layer.msg(data.msg);
                                    location.href=data.url;return false;
                                }else if(data.code==-1){
                                    layer.msg(data.msg);return false;
                                }else{
                                    layer.msg(data.msg);
                                    location.href=data.url;return false;
                                }
                            }
                        });
                    }

                });

            });


        </script>

    </div>
</div>
{include file="default/base/mall_footer" /}
